//
//  AppCommand.swift
//  SwiftUI-Pokemaster
//
//  Created by gree on 2020/10/10.
//

import Foundation

protocol AppCommand {
    func execute(in store: Store)
}

struct LoginAppCommand: AppCommand {
    
    let email: String
    let password: String
    
    func execute(in store: Store) {
        _ = LoginRequest(
            email: email,
            password: password)
            .publisher
            .sink(
                receiveCompletion: { complete in
                if case .failure(let error) = complete {
                    store.dispatch(
                        .accountBehaviorDone(result: .failure(error))
                    )
                }
            }, receiveValue: { user in
                store.dispatch(
                    .accountBehaviorDone(result: .success(user))
                )
            })
    }
    
}
